[#include "/app/common/layout/__backstagemainlayout.html"/]
[#assign pageCss]
<link rel="stylesheet" href="${ContextPath}/plugin/ztree/css/zTreeStyle/zTreeStyle.css" />

[/#assign]
[#assign pageJavascript]
<script src="${ContextPath}/plugin/ztree/js/jquery.ztree.core-3.5.js"></script>
<script src="${ContextPath}/plugin/ztree/js/jquery.ztree.excheck-3.5.js"></script>
<SCRIPT type="text/javascript">
		
		var setting = {
			async:{
				enable : true,
				url:'${ContextPath}/admin/branch/treeData',
				type : "post"
			},
			check:{
				enable:true,
				chkStyle:"checkbox",
				chkboxType: { "Y": "ps", "N": "ps" },
				autoCheckTrigger: true,
			},
			data:{
				simpleData:{
					enable:true,
					idKey:"id",
					pIdKey:"pId",
					rootPId:0,
				},
			},
			view:{
				showIcon: true,
				showLine: true,
			},
		};
		
		function setCheckValue(ids){
			if(apartmentIds != checkedApartmentNodeIds){
				$.ajax({
				   	type: "POST",
				   	url: "${ContextPath!}/admin/branch/setApartment",
				   	data: { "ids" : ids,  "apartmentIds" : checkedApartmentNodeIds},
					async : false,
				   	success: function(data){
				   		if(data != "error"){
							
				     	}else{
				     		alert("设置角色拥有的功能失败！");
				     	}
				   	}
				});
			}
		}
		
		$(document).ready(function(){
			$('.mytree').click(function(){
				$('#zTree').modal();
				$.fn.zTree.init($("#treeDemo"), setting);
			});
		});
		
	</SCRIPT>
[/#assign]
[@mainlayout pageJavascript=pageJavascript pageCss=pageCss currentMenu="organizationFlag-branchFlag-branchsListFlag"]

<div class="page-header">
	<h1>
		单位管理 
		<small> <i class="ace-icon fa fa-angle-double-right"></i> 单位列表</small>
	</h1>
</div>
<form class="bs-example bs-example-form" role="form" action="${ContextPath}/admin/branch" method="post">
	<div class="row">
			<div class="col-xs-4" >
				<div class="input-group">
					<span class="input-group-addon">关键字</span> 
					<input class="form-control" id="branch" name="branch" value="${(branch)!}" placeholder="单位名称" type="text" autocomplete="off">
					<span class="input-group-btn">
						<button class="btn btn-sm btn-default">
							<span class="glyphicon glyphicon-search"></span> 查询
						</button>
					</span>
				</div>
			</div>
	</div>
</form>
<div class="hr hr-dotted"></div>
<table class="table table-bordered table-hover">
		<thead>
			<tr>
				<th width="2%">序号</th>
				<th width="10%">单位名称</th>
				<th width="5%">创建时间</th>
				<th width="4%">状态</th>
				<th width="4%">操作</th>
			</tr>
		</thead>
		<tbody>
			[#list branchPage.getList() as branch]
			<tr>
				<td>${(branch_index+1)!}</td>
				<td> ${(branch.name)!}</td>
				<td> ${(branch.created_at)!}</td>
				<td>
					<b>
					[#if branch.deleted_at??]
					<span class="red">禁用</span>
					[#else]
					<span class="gray">正常</span>
					[/#if]
					</b>
				</td>
				<td>
				<div class="action-buttons">
				<a class="btn btn-minier btn-primary btn-xs"  href="${ContextPath}/admin/branch/edit?id=${(branch.id)!}" >编辑</a>
				[#if branch.deleted_at??]
				<a class="btn btn-minier btn-danger btn-xs"  href="${ContextPath}/admin/branch/on?id=${(branch.id)!}" >启用</a>
				[#else]
				<a class="btn btn-minier btn-primary btn-xs"  href="${ContextPath}/admin/branch/off?id=${(branch.id)!}" >禁用</a>
				[/#if]
				<a class="btn btn-minier btn-primary btn-xs mytree" href="#" >部门</a>
				</div>
				</td>
			</tr>
			[/#list]
			[#if branchPage.getList().size()!=10]
			[#assign size=(10-branchPage.getList().size())]
				[#list 1..size as t]
					<tr>
						<td>${(branchPage.getList().size()+t)!}</td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
					</tr>
				[/#list]
			[/#if]
		</tbody>
	</table>
	[#include "/app/common/inc/_paginate.html" /]
	[@paginate currentPage=branchPage.pageNumber totalPage=branchPage.totalPage actionUrl="/admin/branch/" /]
	[#include "branch/_apartmentTree.html" /]
[/@mainlayout]